<html>
<head>
<script src="../../main/resources/net/pimpas/web/jsf/components/js/pimpas/pimpas.js"></script>
<script>
// detect
pimpas.RequireJS( 'detect.js' );
// timer
pimpas.RequireJS( 'timer.js' );
// interval
pimpas.RequireJS( 'interval.js' );
// listener
pimpas.RequireJS( 'listener.js' );
// log
pimpas.RequireJS( 'log.js' );
// firebug
pimpas.RequireJS( 'firebug.js' );
// dom
pimpas.RequireJS( 'dom.js' );
// dom event
pimpas.RequireJS( 'event.js' );
// validate
pimpas.RequireJS( 'validate.js' );
// httprequest
pimpas.RequireJS( 'httpRequest.js' );
// ajax
pimpas.RequireJS( 'ajax.js' );
// ajaxpopulate
pimpas.RequireJS( 'ajaxPopulate.js' );
// input
pimpas.RequireJS( 'populate/input.js' );
// select
pimpas.RequireJS( 'populate/select.js' );
// radio
pimpas.RequireJS( 'populate/radio.js' );
// checkbox
pimpas.RequireJS( 'populate/checkbox.js' );
// html
pimpas.RequireJS( 'populate/html.js' );
// xml
pimpas.RequireJS( 'xml.js' );
// xpath
pimpas.RequireJS( 'xpath.js' );
// json
pimpas.RequireJS( 'json.js' );
// control
pimpas.RequireJS( 'control/ajaxControl.js');
// utils
pimpas.RequireJS( 'utils/ajaxUtils.js');
</script>
<style>
</style>
<script>
pimpas.FireBug.installLogInConsole( );
myValidate = new pimpas.Listener();
pimpas.Extends(myValidate,
	{
		callBack: function(evt, obj, value, result) {
			switch(evt) {
				case pimpas.Validate.events.onValidate:
					if(obj.id == 'name') {
						var msg = new pimpas.Validate.Message(pimpas.Validate.level.ERROR, obj, "only the name 'pc' is allowed!");
						if(value == null || value != 'pc')
							result.addMessage(msg);	
					} else if(obj.id == 'foods') {
						if(value == null || value == '') {
							var msg = new pimpas.Validate.Message(pimpas.Validate.level.ERROR, obj, "Select at less one food!");
							result.addMessage(msg);	
						}
					}
				break;
			}
		}
	}
);
function validate() {
	// send the id's and listeners
	var result = pimpas.Validate.validate( new Array('name', 'foods'), new Array(myValidate) );
	if(result.hasErrors()) {
		// get all errors
		var errors = result.byLevel( pimpas.Validate.level.ERROR );
		for(var i=0;i<errors.length;i++)
			alert('Field: '+errors[i].obj.id+ ': Message => '+errors[i].message);
		return false;
	}
	return true;
}
</script>
</head>
<body>
<form onSubmit="return validate()">
	<input type="text" id="name" name="name"/>
	<br/>
	Food:<br/>
	<input type="checkbox" id="foods" name="foods" value="0"/>Fish<br>
	<input type="checkbox" name="foods" value="1"/>Meat<br>
	<input type="submit" id="send" value="Send">
</form>
</body>
</html>